package com.mezz.bones.im.common.enums;
import com.mezz.bones.im.common.message.body.in.*;
import com.mezz.bones.im.common.message.body.out.ConversationRecordRes;
import com.mezz.bones.im.common.message.body.out.ConversationPrivateInfoRes;
import com.mezz.bones.im.common.message.body.out.PrivateMessageRecordRes;
import com.mezz.bones.im.common.message.body.out.UserLoginRes;
import com.mezz.bones.im.common.result.ImResultCode;
import com.mezz.bones.im.common.exception.ImBaseException;
import lombok.Getter;

/**
 * 客户端发起的长连接行为
 *
 * 命名规则
 * 客户端主动发起的请求 命名格式：client_
 * 服务端主动发起的请求 命名格式：server_
 */
@Getter
public enum ActionCodeEnum {


    /**
     * 客户端主动发起的行为
     */
    CLIENT_PING_PONG("client_ping_pong","客户端PING请求",1,0, PingReq.class, NonRes.class),
    CLIENT_LOGOUT("client_logout","客户端退出登录请求",0,1, NonReq.class, NonRes.class),

    SERVICE_DEMO("service_demo","业务层演示",1,1, NonReq.class, NonRes.class),

    SERVER_ERROR("server_error","服务端系统错误推送",0,1, NonReq.class, Object.class),

    //用户
    CLIENT_USER_LOGIN("client_user_login","客户端用户登录请求",1,0, UserLoginReq.class, UserLoginRes.class),

    CLIENT_CLOSE_CONNECT("client_close_connect","客户端关闭连接请求",1,0, UserLoginReq.class, UserLoginRes.class),
    SERVER_CLOSE_CONNECT("server_close_connect","服务端关闭连接推送",1,0, UserLoginReq.class, UserLoginRes.class),

    //私聊
    CLIENT_PRIVATE_MESSAGE_CREATE("client_private_message_create","客户端发送单聊消息请求",0,1, PrivateMessageCreateReq.class, PrivateMessageRecordRes.class),
    CLIENT_PRIVATE_MESSAGE_RECORD("client_private_message_record","客户端拉取单聊记录请求",0,1, PrivateMessageRecordReq.class, PrivateMessageRecordRes.class),
    SERVER_PRIVATE_MESSAGE_RECORD("server_private_message_record","服务端单聊记录推送",0,1, PrivateMessageRecordReq.class, PrivateMessageRecordRes.class),


    CLIENT_PRIVATE_MESSAGE_REMOVE("client_private_message_remove","客户端消息记录删除请求",0,1, PrivateMessageRemoveReq.class, NonRes.class),


    CLIENT_MESSAGE_HAS_BEAN_READ("client_message_has_bean_read","客户端会话消息记录已读回执请求",0,1, MessageHasBeenReadReq.class, NonRes.class),

    //会话
    CLIENT_CONVERSATION_RECORD("client_conversation_record","客户端拉取会话列表信息请求",0,1, ConversationRecordReq.class, ConversationRecordRes.class),
    CLIENT_CONVERSATION_PRIVATE_INFO("client_conversation_private_info","客户端拉取私聊会话中信息请求",0,1, ConversationPrivateInfoReq.class, ConversationPrivateInfoRes.class),
    CLIENT_CONVERSATION_USER_REMOVE("client_conversation_user_remove","客户端用户删除会话请求",0,1, ConversationRemoveReq.class, NonRes.class),
    CLIENT_CONVERSATION_USER_TOP("client_conversation_user_top","客户端用户置顶会话请求",0,1, ConversationTopReq.class, NonRes.class),
    CLIENT_CONVERSATION_CLEAR_UNREAD_COUNT("client_conversation_clear_unread_count","客户端清空会话未读数请求",0,1, ConversationClearUnreadCountReq.class, NonRes.class),

    /**
     * 服务端信令  发送信令客户端主动拉取对应数据
     * 服务端主动发起的行为
     * ReqClass 服务端发起命令的模型
     * ResClass 无效
     */
    SERVER_NOTIFY_PULL_PRIVATE_MESSAGE("server_notify_pull_private_message","服务端通知客户端-主动拉取私聊记录推送",0,1, NotifyPullPrivateMessageReq.class, NonRes.class),
    SERVER_NOTIFY_PULL_CONVERSATION_RECORD("server_notify_pull_conversation_record","服务端通知客户端-主动拉取会话列表信息推送",0,1, NonReq.class, NonRes.class)
    ;


    ActionCodeEnum(String code, String text, Integer authIgnore, Integer codeType, Class req, Class res) {
        this.code = code;
        this.text = text;
        this.authIgnore = authIgnore;
        this.codeType = codeType;
        this.req = req;
        this.res = res;
    }

    private String code;
    private String text;

    /**
     * 是否可匿名请求
     * 1匿名访问 0否
     */
    private Integer authIgnore;

    /**
     * code类型 1业务消息 0系统消息(不经过业务层)
     */
    private Integer codeType;

    /**
     * 请求数据模型
     */
    private Class req;

    /**
     * 响应数据模型
     */
    private Class res;

    public static ActionCodeEnum findEnum(String code){

        for (ActionCodeEnum value : ActionCodeEnum.values()) {

            if (value.getCode().equals(code)) {
                return value;
            }
        }

        throw new ImBaseException(ImResultCode.DATA_NOT_FOUND,"ActionCodeEnum枚举不存在: " + code);
    }
}


